import unittest

from zope.component import getUtility
from Products.CMFCore.utils import getToolByName
from plone.portlets.interfaces import IPortletManager

from tchezope.politica.tests.base import TchezopePoliticaTestCase

class TestSetup(TchezopePoliticaTestCase):
    
    def afterSetUp(self):
        self.types = getToolByName(self.portal, 'portal_types')
        self.actions = getToolByName(self.portal,'portal_actions')
        self.properties = getToolByName(self.portal, 'portal_properties')
            
    def test_portal_title(self):
        self.assertEquals("TcheZope.org", self.portal.getProperty('title'))
    def test_portal_description(self):
        self.assertEquals("Comunidade Zope e Plone Brasileira",
                           self.portal.getProperty('description'))
    def test_google_analytics_id(self):
        """atributo plone_control_panel->site->google_analytics
        Google analytics's id: UA-556373-1
        """
        #import pdb;pdb.set_trace()
        googleAnalyticsId = 'UA-556373-1'
        self.failUnless(googleAnalyticsId in self.properties.site_properties.getProperty('webstats_js'))

    def test_cmf_placeful_workflow_installed(self):
        self.failUnless('portal_placeful_tool' in self.portal.objectIds())
        
    def test_cmf_publicator_installed(self):
        self.failUnless('portal_publicator' in self.portal.objectIds())

    def test_cmf_placeful_workflow_installed(self):
        self.failUnless('portal_placeful_workflow' in self.portal.objectIds())

    def test_feedmixer_installed(self):
        #import pdb;pdb.set_trace()
        pm = getUtility(IPortletManager, name=u'plone.leftcolumn', context=self.portal)
        addablePortlets = [i.title for i in pm.getAddablePortletTypes()]
        self.failUnless('Feed mixer' in addablePortlets)
        
    def test_windowz_installed(self):
        self.failUnless('Window' in self.types.objectIds())

    def test_plone_flash_upload_installed(self):
        self.failUnless('folderflashupload' in self.actions.object.objectIds())
    
    def test_plone_help_center_installed(self):
        for contentType in ('HelpCenterDefinition','HelpCenterInstructionalVideoFolder',
                            'HelpCenter','HelpCenterErrorReference','HelpCenterReferenceManual',
                            'HelpCenterHowTo','HelpCenterErrorReferenceFolder','HelpCenterLink',
                            'HelpCenterFAQFolder','HelpCenterReferenceManualFolder',
                            'HelpCenterReferenceManualSection','HelpCenterInstructionalVideo',
                            'HelpCenterLinkFolder','HelpCenterTutorial','HelpCenterTutorialPage',
                            'HelpCenterReferenceManualPage','HelpCenterTutorialFolder',
                            'HelpCenterFAQ','HelpCenterGlossary','HelpCenterHowToFolder',):
            self.failUnless(contentType in self.types.objectIds(),'%s not in intalled types' % contentType)

    def test_keyword_manager_installed(self):
        self.failUnless('portal_keyword_manager' in self.portal.objectIds())
 
    def test_keyword_manager_installed(self):
        self.failUnless('PlonePopoll' in self.types.objectIds())

    def test_tchezope_tema_installed(self):
        skins = getToolByName(self.portal,'portal_skins')
        layer = skins.getSkinPath('Tema do Tchezope')
        self.failUnless('tchezope_tema_custom_templates' in  layer)
        self.assertEquals('Tema do Tchezope', skins.getDefaultSkin())
        
def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestSetup))
    return suite
